﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FoodManager
{
    public partial class frQuanLyKhachHang : Form
    {
        public frQuanLyKhachHang()
        {
            InitializeComponent();
        }

        private void frQuanLyKhachHang_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'db.tblkhachhang' table. You can move, or remove it, as needed.
            this.tblkhachhangTableAdapter.Fill(this.db.tblkhachhang);

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataTable data = tblkhachhangTableAdapter.GetDataById(Convert.ToInt32(listBox1.SelectedValue));
            if (data.Rows.Count > 0)
            {
                cbTrangThai.Text = Functions.GetStringTrangThai(Convert.ToInt32(data.Rows[0]["trangthai"]));
            }
        }

        private void btnInsert_Click(object sender, EventArgs e)
        {
            this.tblkhachhangTableAdapter.Insert(txtMaKhachHang.Text, txtTen.Text, txtDiachi.Text, txtDienThoai.Text, txtHotline.Text, 
                txtNhanVienPhuTrach.Text, Convert.ToByte(Functions.GetIntTrangThai(cbTrangThai.Text)));
            db.tblkhachhang.Rows.Clear();
            this.tblkhachhangTableAdapter.Fill(this.db.tblkhachhang);
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            this.tblkhachhangTableAdapter.UpdateQuery(Convert.ToInt32(listBox1.SelectedValue), txtMaKhachHang.Text, txtTen.Text, 
                txtDiachi.Text, txtDienThoai.Text, txtHotline.Text, txtNhanVienPhuTrach.Text, Convert.ToByte(Functions.GetIntTrangThai(cbTrangThai.Text)));
            db.tblkhachhang.Rows.Clear();
            this.tblkhachhangTableAdapter.Fill(this.db.tblkhachhang);
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            this.tblkhachhangTableAdapter.DeleteQuery(Convert.ToInt32(listBox1.SelectedValue));
            db.tblkhachhang.Rows.Clear();
            this.tblkhachhangTableAdapter.Fill(this.db.tblkhachhang);
        }


    }
}
